package cn.datacare.orm.mapper.parameter;

import java.lang.reflect.Method;
import java.util.Collections;
import java.util.HashMap;

import static cn.datacare.orm.util.Separator.COMMA;

public class UpdateParameter extends MapperParameter {
	
	public UpdateParameter(Method m, String annoParam){
		super(m,annoParam);
		preCheck();
	}

	protected void preCheck() {
		if (this.annoParam != null && annoParam.length() != 0) {
			paramsName = annoParam.split(COMMA);
		} else {
			this.paramsName = checkFirst(m);
		}

	}
	
	@Override
	public Object get(Object[] array) {
		if(array==null||array.length==0){
			return Collections.EMPTY_MAP;
		}
		HashMap<String,Object> map = new HashMap<>(array.length);
		for(int i=0;i<array.length;i++){			
			map.put(this.paramsName[i], array[i]);
		}
		this.addRoot(map, array[0]);
		return map;
	}
	
	
	
}
